﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using Pixysoft.Framework.Configurations;

namespace Pixysoft.Framework.Reports.Core
{
    class ReportLayout : IReportLayout
    {
        int height;
        int width;
        List<ReportLayoutRow> rows = new List<ReportLayoutRow>();

        private List<ReportComponent> texts = new List<ReportComponent>();

        public ReportLayout()
        {
        }

        public int Height
        {
            get { return height; }
            set
            {
                height = value;
            }
        }

        public int Width
        {
            get { return width; }
            set
            {
                width = value;
            }
        }

        public List<ReportLayoutRow> SerializeRows
        {
            get
            {
                return rows;
            }
            set
            {
                rows = value;
            }
        }

        public List<ReportComponent> SerializeTexts
        {
            get
            {
                return texts;
            }
            set
            {
                texts = value;
            }
        }


        public IReportLayoutRowCollection GetRows()
        {
            return new ProtoGridRowCollection(rows);
        }

        public IReportComponentCollection GetComponents()
        {
            return new ReportComponentCollection(texts);
        }

        public void SetWidth(int width)
        {
            foreach (ReportLayoutRow row in rows)
            {
                row.GetColumns().ResetWidth(width);
            }

            this.Width = width;
        }

        public void SetHeight(int height)
        {
            this.Height = height;

            this.GetRows().ResetHeight(height);
        }

        public void CreateGrid(int rowCount, int colCount)
        {
            if (rowCount < 0 || colCount < 0)
                return;

            this.rows.Clear();

            int colWidth = this.width / colCount;

            int rowHeight = this.height / rowCount;

            for (int i = 0; i < rowCount; i++)
            {
                IReportLayoutRow row = this.GetRows().AddRow(rowHeight);

                for (int j = 0; j < colCount; j++)
                {
                    row.GetColumns().AddColumn(colWidth);
                }
            }
        }

    }
}
